package com.wcity.manage.web.module;

import com.wcity.manage.common.context.Constants;
import com.wcity.manage.common.enums.Code;
import com.wcity.manage.common.exception.CustomException;
import com.wcity.manage.common.utils.JSONUtil;
import com.wcity.manage.common.utils.StringUtil;
import com.wcity.manage.service.ModuleService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created by jn on 2016/12/8.
 * 获取模块controller
 */
@Controller
public class IModuleAct {


    /**
     * 获取自定义模块
     * @param userId
     * @return
     */
    @RequestMapping("module_list_front")
    @ResponseBody
    public Map<String,Object> moduleListFront(String userId){

        if ( !StringUtil.isNumeric( userId ) ) throw new CustomException( Constants.PARAMETER_ERROR, Code.ERROR );

        Map<String,Object> map = JSONUtil.getSuccessJson();

        Object res = moduleService.moduleList( Integer.parseInt( userId ) );

        if ( !( res instanceof Map ) ) throw new CustomException( (String) res, Code.ERROR );

        map.put("moduleList", res);
        return map;
    }

    @Resource private ModuleService moduleService;

}
